package com.hxut.mrs.expression;


import com.hxut.mrs.domain.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * description: MrsExpressionRoot
 * date: 2022/7/9 12:24
 * author: MR.孙
 */
@Component(value = "mrs")
public class MrsExpressionRoot {

    public boolean hasAuthority(String authority){
        //获取当前用户的权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        List<String> permissions = loginUser.getPermissions();

        //判断当前用户的权限是否在权限集合中
        return permissions.contains(authority);
    }

}
